package com.jason.sms.agent.queue;

import java.util.LinkedList;

import com.jason.sms.agent.model.SmsMsg;

public class SmsQueueImpl implements SmsQueue {
	
	private final LinkedList<SmsMsg> smsList = new LinkedList<SmsMsg>();
	
	private Object lock = new Object();
	
	
	public void addMsg(SmsMsg msg){
		synchronized(lock){
			smsList.addLast(msg);
			lock.notifyAll();
		}
	}
	
	public SmsMsg getMsg(){
		SmsMsg msg = null;
		try{
			synchronized(lock){
				while(smsList.size() <=0){
					lock.wait();
				}
				msg = smsList.poll();
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return msg;
	}
	
	

}
